<script lang="ts" setup>
import { columns, formSchemas, searchSchemas } from './meta';

import { BasicCrud } from '@/components/crud';
import { addDept, delDept, listDept, updateDept } from '@/api/system/dept';
import { usePageDataStore } from '@/store/modules/page-data';

defineOptions({
  name: 'DepartmentPage',
});

function handleDepartmentAfterFetch(res: any) {
  usePageDataStore().set('departmentTreeData', res.items);
}
</script>

<template>
  <div>
    <BasicCrud
      tree-table
      tree-field="deptId"
      :pagination="false"
      :table-columns="columns"
      :form-schemas="formSchemas"
      :search-schemas="searchSchemas"
      :request="listDept"
      :create-request="addDept"
      :modify-request="updateDept"
      :delete-request="delDept"
      key-field="deptId"
      @fetch-success="handleDepartmentAfterFetch"
    />
  </div>
</template>

<style lang="less" scoped></style>
